//
//  LoadingViewController.m
//  fugitive
//
//  Created by Eugene Bistolas on 5/31/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "LoadingViewController.h"


@implementation LoadingViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

//This is called by game creator to initially upload ALL game data. 
- (id) initWithStartLocation:(CLLocationCoordinate2D) sloc end:(CLLocationCoordinate2D) eloc duration:(int)t powerups:(int)n {
   self = [super init]; 
   if (self) {
      start = sloc;
      stop = eloc; 
      duration = t;
      numPowerups = n; 
   }
   return self; 
}

//This is called by players trying to load preexisting game data to join game. 
- (id) initPlayerWithGameInstance:(int)ginst {
   self = [super init]; 
   if (self) {
      gameInstance = ginst; 
   }
   return self; 
}

- (void) uploadGameData {
   int newGInstance = 0;
   while (newGInstance == 0) {
      newGInstance = arc4random() % 1000; 
   }
   gameInstance = newGInstance; 
   int currTime = [[NSDate date]timeIntervalSince1970]; 
   currTime += duration * 60 * 60; 
   [ServerEngine registerGameInformationWithInstance:newGInstance endTime:currTime startLocation:start stopLocation:stop]; 
}

- (void) getGameData {

}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
